<?php
class Model_User extends Model {
	public $table="users";
	
	//======= Check username exists or not
	public function check_user($username)
	{
		$this->where("username='$username'");
		$this->getdata($this->table);
		if($this->num_rows()==1)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
	public function check_name($name)
	{
		$this->where("name='$name'");
		$this->getdata($this->table);
		if($this->num_rows()==1)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	//========= Check email exist or not
	public function check_email($email)
		{
			$this->where("email = '$email'");
			$this->getdata($this->table);
			if($this->num_rows()==1)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
	//======= Add new user==============	
		public function add_user($data)
		{
			return $this->insert($this->table,$data);
			
		}
	//====Update user infor
		public function update_user($data,$where)
		{
			$this->where($where);
			return $this->update($this->table,$data);
		}
	//=====Login
		public function login($username)
		{
			$this->where="username='$username' or email='$username'";
			$this->getdata($this->table);
				
		}
	//=====Login
		public function get_user()
		{
			$this->getdata($this->table);
			
		}
	//-------------- Comment Channel----------------
	public function get_comment(){
		$this->getdata($this->comment);
		return $this->fetchAll();
	}
	
	public function add_comment($data)
	{
		$this->insert($this->comment,$data);
	}
	public function delete_comment(){
		$this->delete($this->comment);
	}
	public function update_comment($data){
		$this->update($this->comment,$data);
	}
	
}
